package top.dprkshow.practice.graph;

import edu.princeton.cs.algs4.Bag;

/**
 * @author Kent HAN
 * @date 2021/9/7
 */
public class Graph {
    private final int totalVertices;
    private Bag<Integer>[] adj;

    public Graph(int totalVertices) {
        this.totalVertices = totalVertices;
        adj = (Bag<Integer>[])new Bag[totalVertices];
        for (int i = 0; i < totalVertices; i++) {
            adj[i] = new Bag<>();
        }
    }

    public void addEdge(int vertexA, int vertexB) {
        adj[vertexA].add(vertexB);
        adj[vertexB].add(vertexA);
    }

    public Iterable<Integer> adj(int vertex) {
        return adj[vertex];
    }

    public int getTotalVertices() {
        return totalVertices;
    }
}
